<?php
/**
 * 各功能模块的删除方法:AJAX
 */
class AjaxDeleteController extends Yaf_Controller_Abstract
{
	const NET_OK = 10;
	const NET_NOAUTH = 20;
	/**
	 * 初始化,禁用自动渲染
     * @method init
	 */
	public function init()
	{
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/');
			return false;
		}
		Yaf_Dispatcher::getInstance()->disableView(); // 关闭模板
	}
	private function json($data)
	{
		header('Content-type: application/json');
		echo json_encode($data);
	}
	/**
	 * 删除楼层
	 * @method deleteFloorAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function deleteFloorAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
			return false;
		}
		$params = $_POST;
		echo json_encode($params);
		// $result = net::inst('autoBG')->floorDelete($params);
		// if(isset($result->ret)&&$result->ret == self::NET_OK){
		// 	$response['status'] = 'succeed';
		// 	$response['info'] = $result->msg;
		// }else if(isset($result->ret)&&$result->ret == self::NET_NOAUTH){
		// 	$response['status'] = 'fail';
		// 	$response['info'] = $result->msg;
		// }
		// $this->json($response);	
	}
	/**
	 * 删除路点
	 * @method roadDeleteAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function roadDeleteAction(){
		$user = cookie::get('user');
		if(!$user){
			$this->redirect('/index/login/');
			return false;
		}
		$params = $_POST;
		//echo json_encode($params);
		$result = net::inst('autoBG')->magPointDelete($params);
		//echo json_encode($result);
		if(isset($result->ret)&&$result->ret == self::NET_OK){
			$response['status'] = 'succeed';
			$response['info'] = $result->msg;
		}else if(isset($result->ret)&&$result->ret == self::NET_NOAUTH){
			$response['status'] = 'fail';
			$response['info'] = $result->msg;
		}
		$this->json($response);	
	}
	/**
	 * 删除工作区信息
	 * @method deleteWorkareaAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function deleteWorkareaAction(){
		$params = $_POST;
		//$result = net::inst('autoBG')->workAreaDelete($params);
		if(isset($result->ret)&&$result->ret == self::NET_OK){
			$response['status'] = 'succeed';
			$response['info'] = $result->msg;
		}else if(isset($result->ret)&&$result->ret == self::NET_NOAUTH){
			$response['status'] = 'fail';
			$response['info'] = $result->msg;
		}else{
			$response['status'] = 'error';
			$response['error'] = '服务器连接错误！';
		}
		$this->json($response);	
	}
	
	/**
	 * 删除地图元素信息
	 * @method mapElemDeleteAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function mapElemDeleteAction(){
		
		$this->json($response);	
	}
	/**
	 * 删除料车信息
	 * @method skipDeleteAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function skipDeleteAction(){
		//$id = $this->getRequest()->getRequest();

		
		$this->json($response);	
	}
	/**
	 * 删除料车信息
	 * @method skipDeleteAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function skipDeleteAction(){
		//$id = $this->getRequest()->getRequest();

		
		$this->json($response);	
	}
	/**
	 * 删除充电桩信息
	 * @method deleteTaxAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function chargerDeleteAction(){
		$this->json($response);	
	}
	/**
	 * 删除维修记录信息
	 * @method maintenanceDeleteAction
	 * @return [type]      [description]
	 * @author NewFuture
	 */
	public function maintenanceDeleteAction(){
		
		$this->json($response);	
	}
	/**
	 * 管理员删除
     * @method adminDeleteAction
	 */
	function userDeleteAction(){
		$user = cookie::get('user');
		if (!$user)
		{
			$this->redirect("/index/");
			return;
		}
		$param                    = $this->getRequest();//获取查询参数
		$inParam["adminId"]       = $param->getRequest('adminId');
		$inParam["userId"]        = $user["id"]; 
		$result = net::inst('northBG')->userDelete($inParam);
		if($result->ret == self::NET_OK){
			$response['status'] = "succeed";
			$response['info'] = $result->msg;
		}else{
			$response['status'] = "fail";
			$response['info'] = $result->msg;
		}
		$this->json($response);
	}
	/**
	 * 用户分配权限(特殊赋权列表删除
     * @method tableSpecialDeleteAction
	 */
	function tableSpecialDeleteAction(){
		$user = cookie::get('user');
		if (!$user)
		{
			$this->redirect("/index/");
			return;
		}
		$param                    = $this->getRequest();//获取查询参数
		$inParam["adminId"]       = $param->getRequest('adminId');
		$inParam["permit"]  	  = intval($param->getRequest('permit'));
		$inParam["deptId"]        = $param->getRequest('deptId');
		$function 				  = explode(',',$param->getRequest('functions'));
		for($i=0;$i<count($function)-1;$i++){
			$function_list[$i]=$function[$i];
		}
		$inParam["functionId"] = $function_list;
		$result = net::inst('northBG')->tableSpecialDelete($inParam);
		if($result->ret == self::NET_OK){
			$response['status'] = "succeed";
			$showMsg=$result->msg;
			if(!empty($result->list)&&count($result->list)>0){
				$count = count($result->list);
				$showMsg.='其中';
				for($i=0;$i<$count;$i++){
					$showMsg.=$result->list[$i];
					if($i!=$count-1)
						$showMsg.='';
				}
				$showMsg.='这'.$count.'个权限是全部门权限,因此权限移除后,用户对这'.$count.'个权限使用不变,若想移除,选择"全部门权限"进行移除';
			}
			$response["info"] =$showMsg;
		}else{
			$response['status'] = "fail";
			$response['info'] = $result->msg;
		}
		$this->json($response);
	}
	/**
	 * 角色删除
     * @method roleDeleteAction
	 */
	function roleDeleteAction(){
		$user = cookie::get('user');
		if (!$user)
		{
			$this->redirect("/index/");
			return;
		}
		$param                    = $this->getRequest();//获取查询参数
		$inParam["roleId"]        = $param->getRequest('roleId');
		$inParam["userId"]        = $user["id"]; 
		$result = net::inst('northBG')->roleDelete($inParam);
		if($result->ret == self::NET_OK){
			$response['status'] = "succeed";
			$response['info'] = $result->msg;
		}else{
			$response['status'] = "fail";
			$response['info'] = $result->msg;
		}
		$this->json($response);
	}
}
?>
